package fr.unice.client;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * @author PELLEGRINO Laurent
 * @author TROVATO Alexandre
 * 
 * @version 1.0
 */
@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Playlist implements Serializable {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private String name;

	@Persistent
	private int nbAudioFiles = 0;

	@Persistent
	private List<String> audioFileIDs = new ArrayList<String>();

	/**
	 * 
	 */
	public Playlist() {
	}

	/**
	 * @param name
	 */
	public Playlist(String name) {
		this.name = name;
		this.audioFileIDs = new ArrayList<String>();
	}

	public void add(String audioFileID) {
		if (this.audioFileIDs == null) {
			this.audioFileIDs = new ArrayList<String>();
		}
		this.audioFileIDs.add(audioFileID);
		this.nbAudioFiles++;
	}

	public void remove(String audioFileID) {
		this.audioFileIDs.remove(audioFileID);
		this.nbAudioFiles--;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return this.id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * 
	 * @return
	 */
	public int getNbAudioFiles() {
		return this.nbAudioFiles;
	}

	/**
	 * 
	 * @return
	 */
	public List<String> getAudioFileIDs() {
		return this.audioFileIDs;
	}

	/**
	 * 
	 * @param id
	 */
	public void setAudioFileIDs(List<String> id) {
		this.audioFileIDs = id;
	}

	/**
	 * 
	 * @param nb
	 */
	public void setNbAudioFiles(int nb) {
		this.nbAudioFiles = nb;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
}
